package org.rainbowinverted.charging.device.connect.bl.server.handler;

import org.rainbowinverted.charging.device.api.operation.constants.DeviceOpConstantEnum;
import org.rainbowinverted.charging.device.api.operation.dto.op.DeviceOpDataDTO;
import org.rainbowinverted.charging.device.connect.bl.server.message.out.BlDeviceMessageOut;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author huaiping
 */
@Component
public class BlHandlerFactory {
    /**
     * 读写处理程序映射
     */
    private final static Map<Integer, BlAbstractHandler<?,? extends BlDeviceMessageOut>> READ_WRITE_HANDLER_MAP = new HashMap<>(8);
    /**
     * 操作码-帧类型映射
     */
    private final static Map<Integer, Integer> OPCODE_2_FRAME_TYPE_MAP = Map.of(
            DeviceOpConstantEnum.HEARTBEAT.getOpCode(),0x1001,
            DeviceOpConstantEnum.DEVICE_STATUS_REPORT.getOpCode(),0x1002,
            DeviceOpConstantEnum.DEVICE_CHARGE_FINISH_REPORT.getOpCode(),0x1004,
            DeviceOpConstantEnum.START_CHARGE.getOpCode(),0x1007,
            DeviceOpConstantEnum.STOP_CHARGE.getOpCode(),0x1007,
            DeviceOpConstantEnum.UPDATE_DEVICE_FTP.getOpCode(),0x1008,
            DeviceOpConstantEnum.QUERY_DEVICE_STATUS.getOpCode(),0x1003,
            DeviceOpConstantEnum.QUERY_GUN_INFO.getOpCode(),0x1003,
            DeviceOpConstantEnum.DEVICE_EVENT_REPORT.getOpCode(),0x1013,
            DeviceOpConstantEnum.UPDATE_DEVICE_QR.getOpCode(),0x1014);


    /**
     * 获取处理器
     *
     * @param  opCode
     * @return {@link BlAbstractHandler}
     */
    public BlAbstractHandler<?, BlDeviceMessageOut> getHandler(Integer opCode) {
        return (BlAbstractHandler<?, BlDeviceMessageOut>)READ_WRITE_HANDLER_MAP.get(opCode);
    }
}
